package com.example.tilitili.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tilitili.mapper.GoodsMapper;
import com.example.tilitili.mapper.SeckillGoodsMapper;
import com.example.tilitili.pojo.Goods;
import com.example.tilitili.pojo.SeckillGoods;
import com.example.tilitili.pojo.User;
import com.example.tilitili.service.IGoodsService;
import com.example.tilitili.utils.MD5Util;
import com.example.tilitili.utils.ValidatorUtil;
import com.example.tilitili.vo.GoodsVo;
import com.example.tilitili.vo.RegisterVo;
import com.example.tilitili.vo.RespBean;
import com.example.tilitili.vo.RespBeanEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liu
 * @since 2022-01-17
 */
@Service
@Slf4j
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {
    @Resource
    private GoodsMapper goodsMapper;
    /**
     * 返回商品列表
     * @return
     */
    @Override
    public List<GoodsVo> findGoodsVo(){
        return goodsMapper.findGoodsVo();
    }

    /**
     * 获取商品详情
     */
    @Override
    public GoodsVo findGoodsVoByGoodsId(Long goodsId) {
        return goodsMapper.findGoodsVoByGoodsId(goodsId);
    }

    /**
     * 获取上架商品详情
     */
    @Override
    public Goods findGoodsVoByGoodsId2(Long goodsId) {
        return goodsMapper.findGoodsVoByGoodsId(goodsId);
    }

    /**
     * 商品上架
     * @param
     * @return
     */
    @Override
    @Transactional
    public RespBean dogrounding(GoodsVo goodsVo, HttpServletRequest request, HttpServletResponse response) {

        String goodsName=goodsVo.getGoodsName();
        String goodsTitle=goodsVo.getGoodsTitle();
        String goodsImg=goodsVo.getGoodsImg();
        String goodsDetail=goodsVo.getGoodsDetail();
        BigDecimal goodsPrice=goodsVo.getGoodsPrice();
        Integer goodsStock=goodsVo.getGoodsStock();
        String goodsCategory=goodsVo.getGoodsCategory();
//        BigDecimal seckillPrice=goodsVo.getSeckillPrice();
//        Integer stockCount=goodsVo.getStockCount();
//        Date startDate=goodsVo.getStartDate();
//        Date endDate=goodsVo.getEndDate();
        //log.info("{}",mobile)
        Goods goods=grounding(goodsVo);
//        SeckillGoods seckillGoods=grounding2(goodsVo);
//        seckillGoods.setSeckillPrice(seckillPrice);
//        seckillGoods.setStockCount(stockCount);
//        seckillGoods.setStartDate(startDate);
//        seckillGoods.setEndDate(endDate);
//        seckillGoodsMapper.insert(seckillGoods);
        return RespBean.success();
    }
    @Override
    public Goods grounding(GoodsVo goodsVo){
        Goods goods=new Goods();
        goods.setGoodsName(goodsVo.getGoodsName());
        goods.setGoodsTitle(goodsVo.getGoodsTitle());
        goods.setGoodsImg(goodsVo.getGoodsImg());
        goods.setGoodsDetail(goodsVo.getGoodsDetail());
        goods.setGoodsPrice(goodsVo.getGoodsPrice());
        goods.setGoodsStock(goodsVo.getGoodsStock());
        goods.setGoodsCategory(goodsVo.getGoodsCategory());
        goodsMapper.insert(goods);
        return goods;
    }
//    @Override
//    public SeckillGoods grounding2(GoodsVo goodsVo){
//        SeckillGoods seckillGoods=new SeckillGoods();
//        seckillGoods.setSeckillPrice(goodsVo.getSeckillPrice());
//        seckillGoods.setStockCount(goodsVo.getStockCount());
//        seckillGoods.setStartDate((Date)goodsVo.getStartDate());
//        seckillGoods.setEndDate((Date)goodsVo.getEndDate());
//        seckillGoodsMapper.insert(seckillGoods);
//        return seckillGoods;
//    }
}
